#ifndef IO_SERVICE_H
#define IO_SERVICE_H

//////////////////////////////////////////////////////////////////////////
namespace fx {

    FX_DECLARE_CLASS(IoService);

    class IoService
        : public boost::noncopyable
    {
    public:
        static IoServicePtr Inst() 
        {
            return instance_;
        }
        static void Stop()
        {
            Inst()->ios_.stop();
        }
        static void Run()
        {
            boost::system::error_code error;
            Inst()->ios_.run(error);
        }
        static void Post(boost::function<void()> task_handler)
        {
            Inst()->ios_.post(task_handler);
        }
        static boost::asio::io_service& IOS()
        {
            return Inst()->ios_;
        }

    private:
        IoService()
            // : work_(ios_)
        {
        }

        static IoServicePtr instance_;

        boost::asio::io_service ios_;
        // boost::asio::io_service::work work_;
    };

}

#endif//IO_SERVICE_H
